<?php


header("Content-type: application/json; charset=utf-8");
header("Access-Control-Allow-Origin: *");


function check($host,$community){
  $flag=true;
  $sysDescr = @str_replace("STRING:","",snmpget("$host","$community","system.sysDescr.0",1000));
  if($sysDescr){
    $flag=true;
  }else{
    $flag=false;
  }

return $flag;

}


function get_systeminfo($host,$community){

  $sysDescr = @str_replace("STRING:","",snmpget("$host","$community","system.sysDescr.0"));
  $sysObjectID = @str_replace("OID:","",snmpget("$host","$community","system.sysObjectID.0"));
  $sysUpTime = @str_replace("Timeticks:","",snmpget("$host","$community","system.sysUpTime.0"));
  $sysContact = @str_replace("STRING:","",snmpget("$host","$community","sysContact.0"));
  $sysName = @str_replace("STRING:","",snmpget("$host","$community","system.sysName.0"));
  $sysLocation = @str_replace("STRING:","",snmpget("$host","$community","system.sysLocation.0"));
  $sysServices = @str_replace("INTEGER:","",snmpget("$host","$community","system.sysServices.0"));

  $sysarray=array("sysDescr"=>trim($sysDescr),"sysObjectID"=>trim($sysObjectID),"sysUpTime"=>trim($sysUpTime),"sysContact"=>trim($sysContact),"sysName"=>trim($sysName),"sysLocation"=>trim($sysLocation),"sysServices"=>trim($sysServices));

  return $sysarray;

}

if(isset($_POST["url"]))
$url=$_POST["url"];
$art1=array();



  $flag=check("$url","public");
  $sc=true;
  if($flag){
  $info=get_systeminfo("$url","public");
  $sc=true;
  }else{
    $info=array();
    $sc=false;
  }

    $main_arr = array("设备地址" =>$url ,"设备信息"=>$info,"success"=>$sc);


  echo json_encode($main_arr);



